package com.appoint.common.dto;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.log4j.Log4j2;

import java.io.Serializable;

/**
 * 前端返回对象
 *
 * @version 1.0
 * @author baode 2021-1-15
 */
@ApiModel(value="data", description="结果对象")
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1430633339880116031L;

    /**
     * 成功与否标志
     */
    @ApiModelProperty(value = "交易状态 10.成功 11.异常 |其他为失败",example = "10")
    private String resultCode = ResultCode.SUCC;
    /**
     * 成功与否标志
     */
    @ApiModelProperty(value = "交易结果描述",example = "交易成功")
    private String resultMsg = "交易成功";
    /**
     * 返回状态码，为空则默认200.前端需要拦截一些常见的状态码如403、404、500等
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @ApiModelProperty(value = "返回状态码，为空则默认200.前端需要拦截一些常见的状态码如403、404、500等",hidden = true)
    private Integer status;
    /**
     * 编码，可用于前端处理多语言，不需要则不用返回编码
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @ApiModelProperty(value = "编码，可用于前端处理多语言，不需要则不用返回编码",hidden = true)
    private String code;
    /**
     * 相关消息
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @ApiModelProperty(value = "相关消息",hidden = true)
    private String msg;
    /**
     * 相关数据
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @ApiModelProperty(value = "相关数据")
    private T data;


    public Result() {}

    public Result(String resultCode) {
        this.resultCode = resultCode;
    }

    public Result(String resultCode, Integer status) {
        this.resultCode = resultCode;
        this.status = status;
    }

    public Result(String resultCode, String resultMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
    }

    public Result(T data) {
        this.data = data;
    }

    public Result(String resultCode, String code, String msg){
        this(resultCode);
        this.code = code;
        this.msg = msg;
    }

    public Result(String resultCode, Integer status, String code, String msg) {
        this.resultCode = resultCode;
        this.status = status;
        this.code = code;
        this.msg = msg;
    }

    public Result(String resultCode, String code, String msg, T data){
        this(resultCode);
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getResultCode() {
        return resultCode;
    }

    public void setResultCode(String resultCode) {
        this.resultCode = resultCode;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    @Override
    public String toString() {
        String dataStr = data == null ? "" : JSON.toJSONString(data);
        return "{" +
                "resultCode='" + resultCode + '\'' +
                ", resultMsg='" + resultMsg + '\'' +
                ", status=" + status +
                ", code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + dataStr  +
                '}';
    }
}
